﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
using System.Data.SqlClient;
using System.Data;
namespace WcfService
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in code, svc and config file together.
    public class SoftwareItems : IService
    {
        public List<Top10> GetTop10(String categoryId)
        {
            SqlConnection objConnection = new SqlConnection();
            DataSet ObjDataset = new DataSet();
            SqlDataAdapter objAdapater = new SqlDataAdapter();
            SqlCommand objCommand = new SqlCommand("dbo.GetTop10 " + categoryId);
            List<Top10> ItemsList = new List<Top10>();
            //    objConnection.ConnectionString =
            //System.Configuration.ConfigurationManager.ConnectionStrings
            //["ConnStr"].ToString();
            objConnection.ConnectionString = "workstation id=silverDb.mssql.somee.com;packet size=4096;user id=silver;pwd=scorpion123;data source=silverDb.mssql.somee.com;persist security info=False;initial catalog=silverDb";
            objConnection.Open();
            objCommand.Connection = objConnection;
            objAdapater.SelectCommand = objCommand;
            objAdapater.Fill(ObjDataset);
            foreach (DataRow row in ObjDataset.Tables[0].Rows)
            {
                Top10 item = new Top10();
                //objCustomer.Cat_Code1 = ObjDataset.Tables[0].Rows[0][0].ToString();
                item.Name1 = row["Name"].ToString();
                item.Cat_Code1 = row["Cat_Code"].ToString();
                item.Description1 = row["Description"].ToString();
                item.Video_URL1 = row["Video_URL"].ToString();
                item.Platform1 = row["Platform"].ToString();
                item.Resolution1 = row["Resolution"].ToString();
                item.Price1 = row["Price"].ToString();
                item.Size1 = row["Size"].ToString();
                item.Upload_Date1 = row["Upload_Date"].ToString();
                ItemsList.Add(item);
            }
            objConnection.Close();
            return ItemsList;
        }
    }  
}
